<?php
require_once('pworks/mvc/IResult.iface.php');

/**
 * Enter description here...
 *
 */

class RedirectResult implements IResult {
    
    /**
     * 
     * Support to using variables for attribute "src" 
     *
     * @var string
     */
    private static $pattern = '/^\$.+/';
    
	public function show(IAction &$action, ResultConfig $config) {
	    
		$data = $action->getData();
		
		$src = $config->src;
		
		if(preg_match(self::$pattern, $src)){
            $page_key = substr($src,1);
            $src = $data[$page_key];
            unset($data[$page_key]);
		}
		
		$url  = $src .'?';
		
		if($data) foreach($data as $k=>$v){
		    //if(substr($k,0,4) == 'url_'){
		        $url .= "$k=$v&";
		    //}
		}
		$url  = substr($url,0,-1); 
		header("Location: $url");
	}
}

